﻿/*
#**************************************************************************
#  openSIS is a student information system for public and non-public 
#  schools from Open Solutions for Education, Inc. web: www.os4ed.com
#
#  openSIS is  web-based, open source, and comes packed with features that 
#  include student demographic info, scheduling, grade book, attendance, 
#  report cards, eligibility, transcripts, parent portal, 
#  student portal and more.   
#
#  Visit the openSIS web site at http://www.opensis.com to learn more.
#  If you have question regarding this system or the license, please send 
#  an email to info@os4ed.com.
#
#  This program is released under the terms of the GNU General Public License  
#  as  published by the Free Software Foundation, version 2 of the License. 
#  See license.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#**************************************************************************** 

*/

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using OpenSIS.OpenSISWCFServiceReference;
using OpenSISStudentListControl;

namespace OpenSIS.Student
{
    public partial class ViewFormLayout : System.Web.UI.Page
    {
        private HtmlTableRow dTRow;
        private HtmlTableCell dTCell;
        private HtmlTableCell dTCell2;
        private HtmlTable dTAdd;
        private HtmlTableRow dTAddRow;
        private HtmlTableCell dTAddCell;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {              
                //PopulateStudent360Tree();
                PopulateCategoryTree();
                PopulateFieldsInPageLoad();
                mvFormLayout.ActiveViewIndex = 1;
            }
            PopulateSummaryFields();
        }

        //protected void PopulateFieldsInPageLoad()
        //{
        //    //tvStudent360.Nodes[1].Selected = true;
        //    tvCategoryList.Nodes[0].Selected = true;
        //    lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
        //    ViewFormLayoutBL categoryfields = new ViewFormLayoutBL();
        //    StudentSetupBL StSuBL = new StudentSetupBL();
        //    ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //    hdnSchoolId.Value = ddlSchoolName.SelectedItem.Value;
        //    categoryfields.CategoryId = Convert.ToInt32("1");
        //    hdnCatId.Value = "1";
        //    ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //    categoryfields.SchoolId = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //    DataTable dt = categoryfields.GetFieldsByCategory();
        //    rptrFields.DataSource = dt;
        //    rptrFields.DataBind();
        //}              

        //public void PopulateStudent360Tree()
        //{
        //    try
        //    {

        //        tvStudent360.Nodes.Clear();


        //        TreeNode TreeNodeDashboard = new TreeNode();

        //        TreeNodeDashboard.Text = "Dashboard";
        //        TreeNodeDashboard.Value = Convert.ToString("0");
        //        TreeNodeDashboard.ImageUrl = "~/App_Themes/main/images/icon_dashboard.png";
        //        tvStudent360.Nodes.Add(TreeNodeDashboard);

        //        TreeNode TreeNodeGeneralInfo = new TreeNode();
        //        TreeNodeGeneralInfo.Text = "General Info";
        //        TreeNodeGeneralInfo.Value = Convert.ToString("1");
        //        TreeNodeGeneralInfo.ImageUrl = "~/App_Themes/main/images/icon_generalinfo.png";
        //        tvStudent360.Nodes.Add(TreeNodeGeneralInfo);

        //        TreeNode TreeNodeAttendance = new TreeNode();
        //        TreeNodeAttendance.Text = "Attendance";
        //        TreeNodeAttendance.Value = Convert.ToString("2");
        //        TreeNodeAttendance.ImageUrl = "~/App_Themes/main/images/icon_attendance.png";
        //        tvStudent360.Nodes.Add(TreeNodeAttendance);

        //        TreeNode TreeNodeSchedule = new TreeNode();
        //        TreeNodeSchedule.Text = "Schedule";
        //        TreeNodeSchedule.Value = Convert.ToString("3");
        //        TreeNodeSchedule.ImageUrl = "~/App_Themes/main/images/icon_schedule.png";
        //        tvStudent360.Nodes.Add(TreeNodeSchedule);

        //        TreeNode TreeNodeGrades = new TreeNode();
        //        TreeNodeGrades.Text = "Grades";
        //        TreeNodeGrades.Value = Convert.ToString("4");
        //        TreeNodeGrades.ImageUrl = "~/App_Themes/main/images/icon_grades.png";
        //        tvStudent360.Nodes.Add(TreeNodeGrades);

        //        TreeNode TreeNodeEligibility = new TreeNode();
        //        TreeNodeEligibility.Text = "Eligibility";
        //        TreeNodeEligibility.Value = Convert.ToString("5");
        //        TreeNodeEligibility.ImageUrl = "~/App_Themes/main/images/icon_eligibility.png";
        //        tvStudent360.Nodes.Add(TreeNodeEligibility);

        //        TreeNode TreeNodeDiscipline = new TreeNode();
        //        TreeNodeDiscipline.Text = "Discipline";
        //        TreeNodeDiscipline.Value = Convert.ToString("6");
        //        TreeNodeDiscipline.ImageUrl = "~/App_Themes/main/images/icon_discipline.png";
        //        tvStudent360.Nodes.Add(TreeNodeDiscipline);

        //        TreeNode TreeNodeBilling = new TreeNode();
        //        TreeNodeBilling.Text = "Billing";
        //        TreeNodeBilling.Value = Convert.ToString("7");
        //        TreeNodeBilling.ImageUrl = "~/App_Themes/main/images/icon_billing.png";
        //        tvStudent360.Nodes.Add(TreeNodeBilling);








        //        tvStudent360.ExpandAll();
        //    }
        //    catch { }

        //}
        //protected void tvStudent360_SelectedNodeChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        foreach (TreeNode tn in tvCategoryList.Nodes)
        //        {

        //            tn.Selected = false;
        //        }
        //        mvFormLayout.ActiveViewIndex = Convert.ToInt32(tvStudent360.SelectedNode.Value);
        //        if (Convert.ToInt32(tvStudent360.SelectedNode.Value) == 1)
        //        {
        //            ViewFormLayoutBL categoryfields = new ViewFormLayoutBL();

        //            ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");

        //            categoryfields.CategoryId = 1;
        //            hdnCatId.Value = "1";
        //            ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //            categoryfields.SchoolId = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //            DataTable dt = categoryfields.GetFieldsByCategory();
        //            rptrFields.DataSource = dt;
        //            rptrFields.DataBind();
        //            tvCategoryList.Nodes[0].Selected = true;
        //            //foreach (TreeNode tn in tvCategoryList.Nodes)
        //            //{
        //            //    string t = tn.Value.Split(",".ToCharArray())[0];
        //            //    if (t == dt.Rows[3][11].ToString())
        //            //    {

        //            //        tn.Selected = true;

        //            //    }

        //            //}
        //            tvStudent360.Nodes[1].Selected = true;
        //            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";


        //        }
        //        else
        //        {
        //            rptrFields.DataSource = null;
        //            rptrFields.DataBind();
        //        }
        //        phAllFieldHolder.Controls.Clear();
        //    }
        //    catch { }
        //}
        protected void PopulateFieldsInPageLoad()
        {
            // tvStudent360.Nodes[1].Selected = true;
            tvCategoryList.Nodes[0].Selected = true;
            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
            OpenSISWCFStudentViewFormLayoutClient SpClientStudentCatFld = new OpenSISWCFStudentViewFormLayoutClient();
            hdnSchoolId.Value = Session["SchoolID"].ToString();
            Session["CategoryID"] = Convert.ToInt32("1");
            hdnCatId.Value = "1";
            int SchoolId = Convert.ToInt32(Session["SchoolID"]);
            DataTable dt = SpClientStudentCatFld.GetFieldsByCategoryViewFormLayout(SchoolId,Convert.ToInt32(hdnCatId.Value), Session["MLUICulture"].ToString());
            SpClientStudentCatFld.Close();
            rptrFields.DataSource = dt;
            rptrFields.DataBind();
        }           

        //public void PopulateCategoryTree()
        //{
        //    try
        //    {
        //        StudentSetupBL schoolcategory = new StudentSetupBL();
        //        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //        schoolcategory.SchoolId = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        DataTable dt = schoolcategory.GetSchoolSpecificCategory();
        //        tvCategoryList.Nodes.Clear();
        //        string[,] CategoryData = new string[100, 4];
        //        for (int i = 0; i < dt.Rows.Count; i++)
        //        {
        //            TreeNode TreeNodeCategory = new TreeNode();
        //            CategoryData[i, 0] = dt.Rows[i]["Cat_Name"].ToString();
        //            CategoryData[i, 1] = dt.Rows[i]["Cat_Id"].ToString();

        //            TreeNodeCategory.Text = CategoryData[i, 0];

        //            TreeNodeCategory.Value = CategoryData[i, 1];
        //            tvCategoryList.Nodes.Add(TreeNodeCategory);
        //            tvCategoryList.ExpandAll();
        //        }
        //    }
        //    catch { }
        //}
        public void PopulateCategoryTree()
        {
            try
            {
                OpenSISWCFServiceStudentSetupClient SpClientStudentSetUp = new OpenSISWCFServiceStudentSetupClient();

                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                DataTable dt = SpClientStudentSetUp.GetSchoolSpecificCategory(SchoolId.ToString(), Session["MLUICulture"].ToString());
                SpClientStudentSetUp.Close();
                tvCategoryList.Nodes.Clear();
                string[,] CategoryData = new string[100, 4];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeNode TreeNodeCategory = new TreeNode();
                    CategoryData[i, 0] = dt.Rows[i]["Cat_Name"].ToString();
                    CategoryData[i, 1] = dt.Rows[i]["Cat_Id"].ToString();
                    TreeNodeCategory.Text = CategoryData[i, 0];
                    TreeNodeCategory.Value = CategoryData[i, 1];
                    tvCategoryList.Nodes.Add(TreeNodeCategory);
                    tvCategoryList.ExpandAll();
                }
            }
            catch { }
        }

        //protected void tvCategoryList_SelectedNodeChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        ViewFormLayoutBL categoryfields = new ViewFormLayoutBL();
        //        StudentSetupBL StSuBL = new StudentSetupBL();
        //        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //        hdnSchoolId.Value = ddlSchoolName.SelectedItem.Value;
        //        categoryfields.CategoryId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
        //        hdnCatId.Value = tvCategoryList.SelectedNode.Value.ToString();
        //        ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
        //        categoryfields.SchoolId = Convert.ToInt32(ddlSchoolName.SelectedItem.Value);
        //        DataTable dt = categoryfields.GetFieldsByCategory();
        //        //tvStudent360.Nodes[1].Selected = true;
        //        //foreach (TreeNode tn in tvCategoryList.Nodes)
        //        //{
        //        //    string t = tn.Value.Split(",".ToCharArray())[0];
        //        //    if (t == dt.Rows[0][11].ToString())
        //        //    {

        //        //        tn.Selected = true;

        //        //    }

        //        //}

        //        if (tvCategoryList.SelectedNode.Value.ToString() == "3")
        //        {
        //            rptrFields.DataSource = null;
        //            rptrFields.DataBind();
        //            lblHeader.Text = "";

        //            try
        //            {

        //                HtmlTable dTable = new HtmlTable();
        //                dTable.CellPadding = 0;
        //                dTable.CellSpacing = 10;
        //                dTable.Border = 0;
        //                dTable.BorderColor = "#cccccc";
        //                dTable.Width = "100%";

        //                HtmlTable AddressTable = new HtmlTable();
        //                AddressTable.CellPadding = 2;
        //                AddressTable.CellSpacing = 0;
        //                AddressTable.Border = 0;
        //                AddressTable.BorderColor = "#cccccc";
        //                AddressTable.Width = "100%";

        //                int tRows;
        //                int tCells = 2;
        //                int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);

        //                int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
        //                if (tCellsmod != 0)
        //                {
        //                    tCellsquotient = tCellsquotient + 1;
        //                    int j = dt.Rows.Count;

        //                    DataRow dr = dt.NewRow();
        //                    dt.Rows.Add(dr);

        //                }

        //                for (tRows = 0; tRows < tCellsquotient; tRows++)
        //                {
        //                    tRows = 0;
        //                    if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
        //                    {

        //                        HtmlTableRow dTRow = new HtmlTableRow();


        //                        //-----------------------------------------------------
        //                        for (tCells = 0; tCells < 2; tCells++)
        //                        {
        //                            this.dTAdd = new HtmlTable();
        //                            this.dTAdd.CellPadding = 2;
        //                            this.dTAdd.CellSpacing = 0;
        //                            this.dTAdd.Border = 0;
        //                            //this.dTAdd.BorderColor = "#cccccc";

        //                            this.dTCell = new HtmlTableCell();
        //                            this.dTCell2 = new HtmlTableCell();
        //                            dTCell2.Attributes.Add("class", "bevel_verline");

        //                            dTCell.VAlign = "top";
        //                            dTCell.Align = "left";
        //                            //dTCell.Attributes.Add("class", "darkblue_content");

        //                            // HtmlTableCell dTCell = new HtmlTableCell();

        //                            if (dt.Rows[tRows]["FieldName"].ToString() != "")
        //                            {

        //                                StSuBL.FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
        //                                categoryfields.FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
        //                                int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount();
        //                                if (addressfieldcount > 0)
        //                                {
        //                                    dTCell.InnerHtml = "<div class=heading_bevelline>" + dt.Rows[tRows]["FieldName"].ToString() + "</div><div class=clear_m></div>";

        //                                    DataTable dtaddressfields = categoryfields.GetAddressFieldsByFieldId();
        //                                    // DataRow dra = dtaddressfields.NewRow();
        //                                    //dra["FieldName"] = dt.Rows[tRows]["FieldName"].ToString();
        //                                    // dtaddressfields.Rows.InsertAt(dra,0);
        //                                    int AddressTableRows;
        //                                    int AddressTableCells = 1;
        //                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

        //                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
        //                                    if (AddressTableCellsmod != 0)
        //                                    {
        //                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
        //                                        int j = dtaddressfields.Rows.Count;

        //                                        DataRow dradd = dtaddressfields.NewRow();
        //                                        dtaddressfields.Rows.Add(dradd);

        //                                    }


        //                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
        //                                    {
        //                                        AddressTableRows = 0;
        //                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
        //                                        {

        //                                            this.dTAddRow = new HtmlTableRow();
        //                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
        //                                            {

        //                                                this.dTAddCell = new HtmlTableCell();
        //                                                dTAddCell.Width = "49%";
        //                                                dTAddCell.VAlign = "top";
        //                                                HtmlTableCell dTAddCell1 = new HtmlTableCell();
        //                                                dTAddCell1.Width = "1%";
        //                                                dTAddCell1.VAlign = "top";
        //                                                HtmlTableCell dTAddCell2 = new HtmlTableCell();
        //                                                dTAddCell2.Width = "50%";
        //                                                dTAddCell2.VAlign = "top";

        //                                                dTAddCell.InnerHtml = dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString();


        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    TextBox txt = new TextBox();
        //                                                    txt.ID = "txt";
        //                                                    txt.CssClass = "textbox_date";
        //                                                    dTAddCell2.Controls.Add(txt);

        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    CheckBoxList chk = new CheckBoxList();
        //                                                    chk.ID = "chk";

        //                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
        //                                                    dTAddCell2.Controls.Add(chk);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    RadioButtonList rdb = new RadioButtonList();
        //                                                    rdb.ID = "rdb";

        //                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;

        //                                                    dTAddCell2.Controls.Add(rdb);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    DropDownList ddl = new DropDownList();
        //                                                    ddl.ID = "ddl";
        //                                                    ddl.CssClass = "textbox_date";
        //                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
        //                                                    {
        //                                                        categoryfields.populateState(ref ddl);
        //                                                    }
        //                                                    dTAddCell2.Controls.Add(ddl);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    Label lbl = new Label();
        //                                                    lbl.ID = "lbl";
        //                                                    StudentBL stbl2 = new StudentBL();

        //                                                    dTAddCell2.Controls.Add(lbl);
        //                                                }

        //                                                dTAddRow.Controls.Add(dTAddCell);
        //                                                dTAddRow.Controls.Add(dTAddCell1);
        //                                                dTAddRow.Controls.Add(dTAddCell2);
        //                                                dtaddressfields.Rows.RemoveAt(0);

        //                                            }



        //                                            AddressTableRows = 0;
        //                                            dTAdd.Controls.Add(dTAddRow);


        //                                        }
        //                                        else
        //                                        {
        //                                            break;
        //                                        }
        //                                    }


        //                                    dTCell.Controls.Add(dTAdd);


        //                                }
        //                            }

        //                            //dTRow.Controls.Add(dTCell);
        //                            dTRow.Cells.Add(dTCell);
        //                            if (tCells == 0)
        //                            {
        //                                dTRow.Controls.Add(dTCell2);
        //                            }
        //                            dt.Rows.RemoveAt(0);
        //                            tRows = 0;
        //                        }
        //                        //-----------------------------------------------------
        //                        dTable.Controls.Add(dTRow);


        //                    }
        //                    else
        //                    {
        //                        break;
        //                    }
        //                }

        //                phAllFieldHolder.Controls.Add(dTable);
        //            }
        //            catch (Exception ex)
        //            {
        //                string Ex = ex.ToString();

        //            }
        //        }



        //        else
        //        {
        //            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
        //            rptrFields.DataSource = dt;
        //            rptrFields.DataBind();
        //        }

        //    }
        //    catch { }

        //}
        //protected void tvCategoryList_SelectedNodeChanged(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        OpenSISWCFServiceStudentSetupClient categoryfields = new OpenSISWCFServiceStudentSetupClient();

        //        hdnSchoolId.Value = Session["SchoolID"].ToString();
        //        int CategoryId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
        //        hdnCatId.Value = tvCategoryList.SelectedNode.Value.ToString();
        //        int SchoolId = Convert.ToInt32(Session["SchoolID"]);
        //        DataTable dt = categoryfields.GetFieldsByCategory(CategoryId, SchoolId, Session["MLUICulture"].ToString());
        //        categoryfields.Close();
        //        // tvStudent360.Nodes[1].Selected = true;
        //        //foreach (TreeNode tn in tvCategoryList.Nodes)
        //        //{
        //        //    string t = tn.Value.Split(",".ToCharArray())[0];
        //        //    if (t == dt.Rows[0][11].ToString())
        //        //    {
        //        //        tn.Selected = true;
        //        //    }
        //        //}
        //        if (tvCategoryList.SelectedNode.Value.ToString() == "3")
        //        {
        //            rptrFields.DataSource = null;
        //            rptrFields.DataBind();
        //            lblHeader.Text = "";
        //            try
        //            {
        //                HtmlTable dTable = new HtmlTable();
        //                dTable.CellPadding = 0;
        //                dTable.CellSpacing = 10;
        //                dTable.Border = 0;
        //                dTable.BorderColor = "#cccccc";
        //                dTable.Width = "100%";
        //                HtmlTable AddressTable = new HtmlTable();
        //                AddressTable.CellPadding = 2;
        //                AddressTable.CellSpacing = 0;
        //                AddressTable.Border = 0;
        //                AddressTable.BorderColor = "#cccccc";
        //                AddressTable.Width = "100%";
        //                int tRows;
        //                int tCells = 2;
        //                int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);
        //                int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
        //                if (tCellsmod != 0)
        //                {
        //                    tCellsquotient = tCellsquotient + 1;
        //                    int j = dt.Rows.Count;
        //                    DataRow dr = dt.NewRow();
        //                    dt.Rows.Add(dr);
        //                }
        //                for (tRows = 0; tRows < tCellsquotient; tRows++)
        //                {
        //                    tRows = 0;
        //                    if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
        //                    {
        //                        HtmlTableRow dTRow = new HtmlTableRow();
        //                        //-----------------------------------------------------
        //                        for (tCells = 0; tCells < 2; tCells++)
        //                        {
        //                            this.dTAdd = new HtmlTable();
        //                            this.dTAdd.CellPadding = 2;
        //                            this.dTAdd.CellSpacing = 0;
        //                            this.dTAdd.Border = 0;
        //                            //this.dTAdd.BorderColor = "#cccccc";
        //                            this.dTCell = new HtmlTableCell();
        //                            this.dTCell2 = new HtmlTableCell();
        //                            dTCell2.Attributes.Add("class", "bevel_verline");
        //                            dTCell.VAlign = "top";
        //                            dTCell.Align = "left";
        //                            //dTCell.Attributes.Add("class", "darkblue_content");
        //                            // HtmlTableCell dTCell = new HtmlTableCell();
        //                            if (dt.Rows[tRows]["FieldName"].ToString() != "")
        //                            {
        //                                OpenSISWCFServiceStudentSetupClient SPClientDAFC = new OpenSISWCFServiceStudentSetupClient();
        //                                int FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
        //                                int addressfieldcount = SPClientDAFC.CheckDefaultAddressFieldCount(FieldId);
        //                                SPClientDAFC.Close();
        //                                if (addressfieldcount > 0)
        //                                {
        //                                    dTCell.InnerHtml = "<div class=heading_bevelline>" + dt.Rows[tRows]["FieldName"].ToString() + "</div><div class=clear_m></div>";
        //                                    OpenSISWCFServiceStudentSetupClient SPClientGAD = new OpenSISWCFServiceStudentSetupClient();
        //                                    DataTable dtaddressfields = SPClientGAD.GetAddressFieldsByFieldId(SchoolId, FieldId, Session["MLUICulture"].ToString());
        //                                    SPClientGAD.Close();
        //                                    // DataRow dra = dtaddressfields.NewRow();
        //                                    //dra["FieldName"] = dt.Rows[tRows]["FieldName"].ToString();
        //                                    // dtaddressfields.Rows.InsertAt(dra,0);
        //                                    int AddressTableRows;
        //                                    int AddressTableCells = 1;
        //                                    int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);
        //                                    int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
        //                                    if (AddressTableCellsmod != 0)
        //                                    {
        //                                        AddressTableCellsquotient = AddressTableCellsquotient + 1;
        //                                        int j = dtaddressfields.Rows.Count;
        //                                        DataRow dradd = dtaddressfields.NewRow();
        //                                        dtaddressfields.Rows.Add(dradd);
        //                                    }
        //                                    for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
        //                                    {
        //                                        AddressTableRows = 0;
        //                                        if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
        //                                        {
        //                                            this.dTAddRow = new HtmlTableRow();
        //                                            for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
        //                                            {

        //                                                this.dTAddCell = new HtmlTableCell();
        //                                                dTAddCell.Width = "49%";
        //                                                dTAddCell.VAlign = "top";
        //                                                HtmlTableCell dTAddCell1 = new HtmlTableCell();
        //                                                dTAddCell1.Width = "1%";
        //                                                dTAddCell1.VAlign = "top";
        //                                                HtmlTableCell dTAddCell2 = new HtmlTableCell();
        //                                                dTAddCell2.Width = "50%";
        //                                                dTAddCell2.VAlign = "top";
        //                                                dTAddCell.InnerHtml = dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString();
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    TextBox txt = new TextBox();
        //                                                    txt.ID = "txt";
        //                                                    txt.CssClass = "textbox_date";
        //                                                    dTAddCell2.Controls.Add(txt);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    CheckBoxList chk = new CheckBoxList();
        //                                                    chk.ID = "chk";
        //                                                    chk.RepeatDirection = RepeatDirection.Horizontal;
        //                                                    dTAddCell2.Controls.Add(chk);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    RadioButtonList rdb = new RadioButtonList();
        //                                                    rdb.ID = "rdb";
        //                                                    rdb.RepeatDirection = RepeatDirection.Horizontal;
        //                                                    dTAddCell2.Controls.Add(rdb);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    DropDownList ddl = new DropDownList();
        //                                                    ddl.ID = "ddl";
        //                                                    ddl.CssClass = "textbox_date";
        //                                                    if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
        //                                                    {
        //                                                        StudentListControl SLC = new StudentListControl();
        //                                                        SLC.populateState(ref ddl);
        //                                                    }
        //                                                    dTAddCell2.Controls.Add(ddl);
        //                                                }
        //                                                if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
        //                                                {
        //                                                    dTAddCell1.InnerText = " : ";
        //                                                    Label lbl = new Label();
        //                                                    lbl.ID = "lbl";

        //                                                    dTAddCell2.Controls.Add(lbl);
        //                                                }
        //                                                dTAddRow.Controls.Add(dTAddCell);
        //                                                dTAddRow.Controls.Add(dTAddCell1);
        //                                                dTAddRow.Controls.Add(dTAddCell2);
        //                                                dtaddressfields.Rows.RemoveAt(0);
        //                                            }
        //                                            AddressTableRows = 0;
        //                                            dTAdd.Controls.Add(dTAddRow);
        //                                        }
        //                                        else
        //                                        {
        //                                            break;
        //                                        }
        //                                    }
        //                                    dTCell.Controls.Add(dTAdd);
        //                                }
        //                            }
        //                            //dTRow.Controls.Add(dTCell);
        //                            dTRow.Cells.Add(dTCell);
        //                            if (tCells == 0)
        //                            {
        //                                dTRow.Controls.Add(dTCell2);
        //                            }
        //                            dt.Rows.RemoveAt(0);
        //                            tRows = 0;
        //                        }
        //                        //-----------------------------------------------------
        //                        dTable.Controls.Add(dTRow);
        //                    }
        //                    else
        //                    {
        //                        break;
        //                    }
        //                }
        //                phAllFieldHolder.Controls.Add(dTable);
        //            }
        //            catch (Exception ex)
        //            {
        //                string Ex = ex.ToString();
        //            }
        //        }
        //        else
        //        {
        //            lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
        //            rptrFields.DataSource = dt;
        //            rptrFields.DataBind();
        //        }

        //    }
        //    catch { }
        //}

        //protected void rptrFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        //{
        //    try
        //    {
        //        ViewFormLayoutBL vmlBL = new ViewFormLayoutBL();
        //        HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
        //        HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
        //        HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
        //        HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
        //        if (hdnDefCus.Value.ToString().Trim() == "D")
        //        {
        //            if (hdnFieldType.Value.ToString() == "1")
        //            {
        //                TextBox txt = new TextBox();
        //                txt.ID = "txt";
        //                txt.Width = 100;
        //                maindiv.Controls.Add(txt);

        //            }
        //            if (hdnFieldType.Value.ToString() == "2")
        //            {
        //                CheckBoxList chk = new CheckBoxList();
        //                chk.ID = "chk";
        //                chk.RepeatDirection = RepeatDirection.Horizontal;
        //                maindiv.Controls.Add(chk);
        //            }
        //            if (hdnFieldType.Value.ToString() == "3")
        //            {
        //                RadioButtonList rdb = new RadioButtonList();
        //                rdb.ID = "rdb";
        //                vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
        //                if (Convert.ToInt32(hdnFieldId.Value) == 10)
        //                {
        //                    vmlBL.PopulateGender(ref rdb);
        //                }
        //                rdb.RepeatDirection = RepeatDirection.Horizontal;
        //                maindiv.Controls.Add(rdb);
        //            }
        //            if (hdnFieldType.Value.ToString() == "4")
        //            {
        //                DropDownList ddl = new DropDownList();
        //                ddl.ID = "ddl";
        //                ddl.CssClass = "textbox_date";
        //                vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
        //                if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
        //                {
        //                    vmlBL.populateEthnicity(ref ddl);
        //                }
        //                if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
        //                {
        //                    vmlBL.populateLanguage(ref ddl);
        //                }
        //                if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
        //                {
        //                    vmlBL.populateCountry(ref ddl);
        //                }
        //                if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
        //                {
        //                    // vmlBL.populateCountry(ref ddl);
        //                    vmlBL.PopulateEnrollCdn(ref ddl);
        //                }
        //                maindiv.Controls.Add(ddl);
        //            }
        //            if (hdnFieldType.Value.ToString() == "5")
        //            {
        //                Label lbl = new Label();
        //                lbl.ID = "lbl";
        //                StudentBL stbl2 = new StudentBL();
        //                maindiv.Controls.Add(lbl);
        //            }


        //        }
        //        else if (hdnDefCus.Value.ToString().Trim() == "C")
        //        {
        //            if (hdnFieldType.Value.ToString() == "1")
        //            {
        //                TextBox txt = new TextBox();
        //                txt.ID = "txt";
        //                txt.Width = 100;

        //                maindiv.Controls.Add(txt);

        //            }
        //            if (hdnFieldType.Value.ToString() == "2")
        //            {
        //                CheckBoxList chk = new CheckBoxList();
        //                chk.ID = "chk";
        //                vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
        //                vmlBL.populatedynamicrchk(ref chk);
        //                chk.RepeatDirection = RepeatDirection.Horizontal;
        //                maindiv.Controls.Add(chk);
        //            }
        //            if (hdnFieldType.Value.ToString() == "3")
        //            {
        //                RadioButtonList rdb = new RadioButtonList();
        //                rdb.ID = "rdb";
        //                vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
        //                vmlBL.populatedynamicrbtn(ref rdb);
        //                rdb.RepeatDirection = RepeatDirection.Horizontal;

        //                maindiv.Controls.Add(rdb);
        //            }
        //            if (hdnFieldType.Value.ToString() == "4")
        //            {
        //                DropDownList ddl = new DropDownList();
        //                ddl.ID = "ddl";
        //                vmlBL.FieldId = Convert.ToInt32(hdnFieldId.Value);
        //                vmlBL.populatedynamicddl(ref ddl);
        //                ddl.AutoPostBack = false;
        //                maindiv.Controls.Add(ddl);

        //            }
        //            if (hdnFieldType.Value.ToString() == "5")
        //            {
        //                Label lbl = new Label();
        //                lbl.ID = "lbl";
        //                StudentBL stbl2 = new StudentBL();

        //                maindiv.Controls.Add(lbl);
        //            }
        //        }

        //        if (hdnDefCus.Value.ToString().Trim() == "D")
        //        {
        //            //if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
        //            //{
        //            //    e.Item.Visible = false;
        //            //}



        //            if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 5 || Convert.ToInt32(hdnFieldId.Value) == 7 || Convert.ToInt32(hdnFieldId.Value) == 109 || Convert.ToInt32(hdnFieldId.Value) == 174 || Convert.ToInt32(hdnFieldId.Value) == 6)
        //            {
        //                e.Item.Visible = false;
        //            }


        //        }
        //    }
        //    catch { }


        //}
        
        protected void tvCategoryList_SelectedNodeChanged(object sender, EventArgs e)
        {
            try
            {
                OpenSISWCFStudentViewFormLayoutClient categoryfields = new OpenSISWCFStudentViewFormLayoutClient();
                OpenSISWCFServiceStudentSetupClient StSuBL = new OpenSISWCFServiceStudentSetupClient();
                StudentListControl StuControl = new StudentListControl();
                //ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                hdnSchoolId.Value = Convert.ToInt32(Session["SchoolID"]).ToString() ;
                int CategoryId = Convert.ToInt32(tvCategoryList.SelectedNode.Value);
                hdnCatId.Value = tvCategoryList.SelectedNode.Value.ToString();
              //  ddlSchoolName = (DropDownList)Page.Master.FindControl("ddlSchoolName");
                int SchoolId = Convert.ToInt32(Session["SchoolID"]);
                DataTable dt = categoryfields.GetFieldsByCategoryViewFormLayout(SchoolId, CategoryId, Session["MLUICulture"].ToString());
                //tvStudent360.Nodes[1].Selected = true;
                //foreach (TreeNode tn in tvCategoryList.Nodes)
                //{
                //    string t = tn.Value.Split(",".ToCharArray())[0];
                //    if (t == dt.Rows[0][11].ToString())
                //    {

                //        tn.Selected = true;

                //    }

                //}

                if (tvCategoryList.SelectedNode.Value.ToString() == "3")
                {
                    rptrFields.DataSource = null;
                    rptrFields.DataBind();
                    lblHeader.Text = "";
                    try
                    {
                        HtmlTable dTable = new HtmlTable();
                        dTable.CellPadding = 0;
                        dTable.CellSpacing = 10;
                        dTable.Border = 0;
                        dTable.BorderColor = "#cccccc";
                        dTable.Width = "100%";

                        HtmlTable AddressTable = new HtmlTable();
                        AddressTable.CellPadding = 2;
                        AddressTable.CellSpacing = 0;
                        AddressTable.Border = 0;
                        AddressTable.BorderColor = "#cccccc";
                        AddressTable.Width = "100%";

                        int tRows;
                        int tCells = 2;
                        int tCellsmod = Convert.ToInt32(dt.Rows.Count % tCells);
                        int tCellsquotient = Convert.ToInt32(dt.Rows.Count / tCells);
                        if (tCellsmod != 0)
                        {
                            tCellsquotient = tCellsquotient + 1;
                            int j = dt.Rows.Count;
                            DataRow dr = dt.NewRow();
                            dt.Rows.Add(dr);
                        }

                        for (tRows = 0; tRows < tCellsquotient; tRows++)
                        {
                            tRows = 0;
                            if (dt.Rows.Count > 0 || dt.Rows.Count != 0)
                            {
                                HtmlTableRow dTRow = new HtmlTableRow();
                                //-----------------------------------------------------
                                for (tCells = 0; tCells < 2; tCells++)
                                {
                                    this.dTAdd = new HtmlTable();
                                    this.dTAdd.CellPadding = 2;
                                    this.dTAdd.CellSpacing = 0;
                                    this.dTAdd.Border = 0;
                                    //this.dTAdd.BorderColor = "#cccccc";

                                    this.dTCell = new HtmlTableCell();
                                    this.dTCell2 = new HtmlTableCell();
                                    dTCell2.Attributes.Add("class", "bevel_verline");

                                    dTCell.VAlign = "top";
                                    dTCell.Align = "left";
                                    //dTCell.Attributes.Add("class", "darkblue_content");

                                    // HtmlTableCell dTCell = new HtmlTableCell();

                                    if (dt.Rows[tRows]["FieldName"].ToString() != "")
                                    {

                                        int FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                       // categoryfields.FieldId = Convert.ToInt32(dt.Rows[tRows]["FieldId"]);
                                        int addressfieldcount = StSuBL.CheckDefaultAddressFieldCount(FieldId);
                                        if (addressfieldcount > 0)
                                        {
                                            dTCell.InnerHtml = "<div class=heading_bevelline>" + dt.Rows[tRows]["FieldName"].ToString() + "</div><div class=clear_m></div>";

                                            DataTable dtaddressfields = categoryfields.GetAddressFieldsByFieldIdViewFormLayout(SchoolId,FieldId,Session["MLUICulture"].ToString());
                                            // DataRow dra = dtaddressfields.NewRow();
                                            //dra["FieldName"] = dt.Rows[tRows]["FieldName"].ToString();
                                            // dtaddressfields.Rows.InsertAt(dra,0);
                                            int AddressTableRows;
                                            int AddressTableCells = 1;
                                            int AddressTableCellsmod = Convert.ToInt32(dtaddressfields.Rows.Count % AddressTableCells);

                                            int AddressTableCellsquotient = Convert.ToInt32(dtaddressfields.Rows.Count / AddressTableCells);
                                            if (AddressTableCellsmod != 0)
                                            {
                                                AddressTableCellsquotient = AddressTableCellsquotient + 1;
                                                int j = dtaddressfields.Rows.Count;

                                                DataRow dradd = dtaddressfields.NewRow();
                                                dtaddressfields.Rows.Add(dradd);

                                            }


                                            for (AddressTableRows = 0; AddressTableRows < AddressTableCellsquotient; AddressTableRows++)
                                            {
                                                AddressTableRows = 0;
                                                if (dtaddressfields.Rows.Count > 0 || dtaddressfields.Rows.Count != 0)
                                                {

                                                    this.dTAddRow = new HtmlTableRow();
                                                    for (AddressTableCells = 0; AddressTableCells < 1; AddressTableCells++)
                                                    {

                                                        this.dTAddCell = new HtmlTableCell();
                                                        dTAddCell.Width = "49%";
                                                        dTAddCell.VAlign = "top";
                                                        HtmlTableCell dTAddCell1 = new HtmlTableCell();
                                                        dTAddCell1.Width = "1%";
                                                        dTAddCell1.VAlign = "top";
                                                        HtmlTableCell dTAddCell2 = new HtmlTableCell();
                                                        dTAddCell2.Width = "50%";
                                                        dTAddCell2.VAlign = "top";

                                                        dTAddCell.InnerHtml = dtaddressfields.Rows[AddressTableRows]["FieldName"].ToString();


                                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "1")
                                                        {
                                                            dTAddCell1.InnerText = " : ";
                                                            TextBox txt = new TextBox();
                                                            txt.ID = "txt";
                                                            txt.CssClass = "textbox_date";
                                                            dTAddCell2.Controls.Add(txt);

                                                        }
                                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "2")
                                                        {
                                                            dTAddCell1.InnerText = " : ";
                                                            CheckBoxList chk = new CheckBoxList();
                                                            chk.ID = "chk";

                                                            chk.RepeatDirection = RepeatDirection.Horizontal;
                                                            dTAddCell2.Controls.Add(chk);
                                                        }
                                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "3")
                                                        {
                                                            dTAddCell1.InnerText = " : ";
                                                            RadioButtonList rdb = new RadioButtonList();
                                                            rdb.ID = "rdb";

                                                            rdb.RepeatDirection = RepeatDirection.Horizontal;

                                                            dTAddCell2.Controls.Add(rdb);
                                                        }
                                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "4")
                                                        {
                                                            dTAddCell1.InnerText = " : ";
                                                            DropDownList ddl = new DropDownList();
                                                            ddl.ID = "ddl";
                                                            ddl.CssClass = "textbox_date";
                                                            if (dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "4" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "13" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "24" || dtaddressfields.Rows[AddressTableRows]["FieldId"].ToString() == "40")
                                                            {
                                                                StuControl.populateState(ref ddl);
                                                            }
                                                            dTAddCell2.Controls.Add(ddl);
                                                        }
                                                        if (dtaddressfields.Rows[AddressTableRows]["FieldType"].ToString() == "5")
                                                        {
                                                            dTAddCell1.InnerText = " : ";
                                                            Label lbl = new Label();
                                                            lbl.ID = "lbl";
                                                            //StudentBL stbl2 = new StudentBL();

                                                            dTAddCell2.Controls.Add(lbl);
                                                        }

                                                        dTAddRow.Controls.Add(dTAddCell);
                                                        dTAddRow.Controls.Add(dTAddCell1);
                                                        dTAddRow.Controls.Add(dTAddCell2);
                                                        dtaddressfields.Rows.RemoveAt(0);

                                                    }



                                                    AddressTableRows = 0;
                                                    dTAdd.Controls.Add(dTAddRow);


                                                }
                                                else
                                                {
                                                    break;
                                                }
                                            }


                                            dTCell.Controls.Add(dTAdd);


                                        }
                                    }

                                    //dTRow.Controls.Add(dTCell);
                                    dTRow.Cells.Add(dTCell);
                                    if (tCells == 0)
                                    {
                                        dTRow.Controls.Add(dTCell2);
                                    }
                                    dt.Rows.RemoveAt(0);
                                    tRows = 0;
                                }
                                //-----------------------------------------------------
                                dTable.Controls.Add(dTRow);


                            }
                            else
                            {
                                break;
                            }
                        }
                        phAllFieldHolder.Controls.Add(dTable);
                    }
                    catch (Exception ex)
                    {
                        string Ex = ex.ToString();
                    }
                }

                else
                {
                    lblHeader.Text = "<div class='heading_bevelline'>" + tvCategoryList.SelectedNode.Text.ToString() + "</div>" + "<div class='clear_m'>" + " " + "</div>";
                    rptrFields.DataSource = dt;
                    rptrFields.DataBind();
                }
            }
            catch { }
        }

        protected void rptrFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                StudentListControl vmlBL = new StudentListControl();
                HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
                HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
                HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");
                HiddenField hdnDefCus = (HiddenField)e.Item.FindControl("hdnDefCus");
                if (hdnDefCus.Value.ToString().Trim() == "D")
                {
                    if (hdnFieldType.Value.ToString() == "1")
                    {
                        TextBox txt = new TextBox();
                        txt.ID = "txt";
                        txt.Width = 100;
                        maindiv.Controls.Add(txt);
                    }
                    if (hdnFieldType.Value.ToString() == "2")
                    {
                        CheckBoxList chk = new CheckBoxList();
                        chk.ID = "chk";
                        chk.RepeatDirection = RepeatDirection.Horizontal;
                        maindiv.Controls.Add(chk);
                    }
                    if (hdnFieldType.Value.ToString() == "3")
                    {
                        RadioButtonList rdb = new RadioButtonList();
                        rdb.ID = "rdb";
                        int FieldId = Convert.ToInt32(hdnFieldId.Value);
                        if (Convert.ToInt32(hdnFieldId.Value) == 10)
                        {
                            vmlBL.PopulateGender(ref rdb);
                        }
                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                        maindiv.Controls.Add(rdb);
                    }
                    if (hdnFieldType.Value.ToString() == "4")
                    {
                        DropDownList ddl = new DropDownList();
                        ddl.ID = "ddl";
                        ddl.CssClass = "textbox_date";
                        int FieldId = Convert.ToInt32(hdnFieldId.Value);
                        if (Convert.ToInt32(hdnFieldId.Value) == 11)//ETHNICITY
                        {
                            //*********18/05/2010***********
                            vmlBL.populateEthnicity(ref ddl, Convert.ToInt32(Session["SchoolID"]));
                        }
                        if (Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 16)//LANGUAGE
                        {
                            vmlBL.populateLanguage(ref ddl);
                        }
                        if (Convert.ToInt32(hdnFieldId.Value) == 18)//COUNTRY
                        {
                            vmlBL.populateCountry(ref ddl);
                        }
                        if (Convert.ToInt32(hdnFieldId.Value) == 120)//START CONDITION
                        {
                            //vmlBL.populateCountry(ref ddl);
                            vmlBL.PopulateEnrollCdn(ref ddl);
                        }
                        maindiv.Controls.Add(ddl);
                    }
                    if (hdnFieldType.Value.ToString() == "5")
                    {
                        Label lbl = new Label();
                        lbl.ID = "lbl";
                        maindiv.Controls.Add(lbl);
                    }
                    //******************change 23/06/10*************
                    if (hdnFieldType.Value.ToString() == "6")
                    {
                        var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                        control.ID = "uc";

                        maindiv.Controls.Add(control);
                    }



                }
                else if (hdnDefCus.Value.ToString().Trim() == "C")
                {
                    if (hdnFieldType.Value.ToString() == "1")
                    {
                        TextBox txt = new TextBox();
                        txt.ID = "txt";
                        txt.Width = 100;
                        maindiv.Controls.Add(txt);
                    }
                    if (hdnFieldType.Value.ToString() == "2")
                    {
                        CheckBoxList chk = new CheckBoxList();
                        chk.ID = "chk";
                        int FieldId = Convert.ToInt32(hdnFieldId.Value);
                        vmlBL.populatedynamicrchk(ref chk, FieldId);
                        chk.RepeatDirection = RepeatDirection.Horizontal;
                        maindiv.Controls.Add(chk);
                    }
                    if (hdnFieldType.Value.ToString() == "3")
                    {
                        RadioButtonList rdb = new RadioButtonList();
                        rdb.ID = "rdb";
                        int FieldId = Convert.ToInt32(hdnFieldId.Value);
                        vmlBL.populatedynamicrbtn(ref rdb, FieldId);
                        rdb.RepeatDirection = RepeatDirection.Horizontal;
                        maindiv.Controls.Add(rdb);
                    }
                    if (hdnFieldType.Value.ToString() == "4")
                    {
                        DropDownList ddl = new DropDownList();
                        ddl.ID = "ddl";
                        int FieldId = Convert.ToInt32(hdnFieldId.Value);
                        vmlBL.populatedynamicddl(ref ddl, FieldId);
                        ddl.AutoPostBack = false;
                        maindiv.Controls.Add(ddl);
                    }
                    if (hdnFieldType.Value.ToString() == "5")
                    {
                        Label lbl = new Label();
                        lbl.ID = "lbl";
                        maindiv.Controls.Add(lbl);
                    }
                    //******************change 23/06/10*************
                    if (hdnFieldType.Value.ToString() == "6")
                    {
                        var control = (DatePicker.DatePicker)Page.LoadControl("~/DatePicker.ascx");

                        control.ID = "uc";

                        maindiv.Controls.Add(control);
                    }

                }
                //if (hdnDefCus.Value.ToString().Trim() == "D")
                //{
                //    if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 13 || Convert.ToInt32(hdnFieldId.Value) == 14 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15)
                //    {
                //        e.Item.Visible = false;
                //    }
                //}
            }
            catch { }
        }

        protected void PopulateSummaryFields()
        {
            try
            {
                OpenSISWCFServiceStudentFormLayoutClient summaryflds = new OpenSISWCFServiceStudentFormLayoutClient();
                DataTable dt = summaryflds.GetSummaryFields();
                summaryflds.Close();
                DataRow dr1 = dt.NewRow();
                dr1["FieldName"] = "Attendance Status";
                dt.Rows.Add(dr1);
                DataRow dr2 = dt.NewRow();
                dr2["FieldName"] = "Current Location";
                dt.Rows.Add(dr2);
                DataRow dr3 = dt.NewRow();
                dr3["FieldName"] = "With Whom";
                dt.Rows.Add(dr3);
                DataRow dr4 = dt.NewRow();
                dr4["FieldName"] = "Med Alert";
                dt.Rows.Add(dr4);
                rptrSummary.DataSource = dt; ;
                rptrSummary.DataBind();
            }
            catch { }
        }

        //protected void rptrSummary_ItemDataBound(object sender, RepeaterItemEventArgs e)
        //{

        //    HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
        //    HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
        //    HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");

        //    if (hdnFieldId.Value != "")
        //    {
        //        if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 13)
        //        {
        //            Label lbl = new Label();
        //            lbl.ID = "lbl";
        //            StudentBL stbl2 = new StudentBL();
        //            if (Convert.ToInt32(hdnFieldId.Value) == 1)
        //            {
        //                lbl.Text = "ABC 9999999999";
        //            }
        //            else if (Convert.ToInt32(hdnFieldId.Value) == 13)
        //            {
        //                lbl.Text = "99-99-9999 | 99 yrs 99 mo";
        //            }
        //            else
        //            {
        //                lbl.Text = "XXXXXXX";
        //            }

        //            maindiv.Controls.Add(lbl);
        //        }
        //    }
        //    else
        //    {
        //        Label lbl = new Label();
        //        lbl.ID = "lbl";
        //        lbl.Text = "XXXXXXX";
        //        maindiv.Controls.Add(lbl);

        //    }

        //    //if (Convert.ToInt32(hdnFieldId.Value) == 13)
        //    //{
        //    //    tdColon.Visible = false;
        //    //}
        //    //if (hdnFieldType.Value.ToString() == "1")
        //    //{
        //    //    TextBox txt = new TextBox();
        //    //    txt.ID = "txt";
        //    //    txt.Width = 100;
        //    //    if (Convert.ToInt32(hdnFieldId.Value) != 13)
        //    //    {
        //    //        maindiv.Controls.Add(txt);
        //    //    }

        //    //}
        //    //if (hdnFieldType.Value.ToString() == "2")
        //    //{
        //    //    CheckBoxList chk = new CheckBoxList();
        //    //    chk.ID = "chk";

        //    //    chk.RepeatDirection = RepeatDirection.Horizontal;
        //    //    maindiv.Controls.Add(chk);
        //    //}
        //    //if (hdnFieldType.Value.ToString() == "3")
        //    //{
        //    //    RadioButtonList rdb = new RadioButtonList();
        //    //    rdb.ID = "rdb";

        //    //    rdb.RepeatDirection = RepeatDirection.Horizontal;

        //    //    maindiv.Controls.Add(rdb);
        //    //}
        //    //if (hdnFieldType.Value.ToString() == "4")
        //    //{
        //    //    DropDownList ddl = new DropDownList();
        //    //    ddl.ID = "ddl";

        //    //    ddl.Items.Add("Select");
        //    //    maindiv.Controls.Add(ddl);

        //    //}
        //    //if (hdnFieldType.Value.ToString() == "5")
        //    //{
        //    //    Label lbl = new Label();
        //    //    lbl.ID = "lbl";
        //    //    StudentBL stbl2 = new StudentBL();

        //    //    maindiv.Controls.Add(lbl);
        //    //}

        //}

        protected void rptrSummary_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HiddenField hdnFieldType = (HiddenField)e.Item.FindControl("hdnFieldType");
            HiddenField hdnFieldId = (HiddenField)e.Item.FindControl("hdnFieldId");
            HtmlControl maindiv = (HtmlControl)e.Item.FindControl("maindiv");

            if (Convert.ToInt32(hdnFieldId.Value) == 1 || Convert.ToInt32(hdnFieldId.Value) == 110 || Convert.ToInt32(hdnFieldId.Value) == 11 || Convert.ToInt32(hdnFieldId.Value) == 15 || Convert.ToInt32(hdnFieldId.Value) == 13)
            {
                Label lbl = new Label();
                lbl.ID = "lbl";
                if (Convert.ToInt32(hdnFieldId.Value) == 1)
                {
                    lbl.Text = "ABC 9999999999";
                }
                else if (Convert.ToInt32(hdnFieldId.Value) == 13)
                {
                    lbl.Text = "99-99-9999 | 99 yrs 99 mo";
                }
                else
                {
                    lbl.Text = "XXXXXXX";
                }
                maindiv.Controls.Add(lbl);
            }

            //if (Convert.ToInt32(hdnFieldId.Value) == 13)
            //{
            //    tdColon.Visible = false;
            //}
            //if (hdnFieldType.Value.ToString() == "1")
            //{
            //    TextBox txt = new TextBox();
            //    txt.ID = "txt";
            //    txt.Width = 100;
            //    if (Convert.ToInt32(hdnFieldId.Value) != 13)
            //    {
            //        maindiv.Controls.Add(txt);
            //    }
            //}
            //if (hdnFieldType.Value.ToString() == "2")
            //{
            //    CheckBoxList chk = new CheckBoxList();
            //    chk.ID = "chk";
            //    chk.RepeatDirection = RepeatDirection.Horizontal;
            //    maindiv.Controls.Add(chk);
            //}
            //if (hdnFieldType.Value.ToString() == "3")
            //{
            //    RadioButtonList rdb = new RadioButtonList();
            //    rdb.ID = "rdb";
            //    rdb.RepeatDirection = RepeatDirection.Horizontal;
            //    maindiv.Controls.Add(rdb);
            //}
            //if (hdnFieldType.Value.ToString() == "4")
            //{
            //    DropDownList ddl = new DropDownList();
            //    ddl.ID = "ddl";
            //    ddl.Items.Add("Select");
            //    maindiv.Controls.Add(ddl);
            //}
            //if (hdnFieldType.Value.ToString() == "5")
            //{
            //    Label lbl = new Label();
            //    lbl.ID = "lbl";
            //    StudentBL stbl2 = new StudentBL();
            //    maindiv.Controls.Add(lbl);
            //}
        }
        
    }
}